--[[
    @desc 队列 下标由0到n-1
    @author zch
    @data:2022-04-19 10:07:00
]]

local Queue = Queue or BaseClass()
local table = table
local table_insert = table.insert
local table_remove = table.remove

function Queue:__init()
	self.size = 0
	self.items = {}
end

-- 队列尾部入队
function Queue:EnQueue(item)
	self.size = self.size + 1
	self.items[self.size] = item
end

-- 队列头部出队 不删除
function Queue:DeQueue()
	if self.size > 0 then
		local item = self.items[1]
		return item
	end
	return nil
end

-- 队列头部出队 删除
function Queue:Peek()
	if self.size > 0 then
		local item = self.items[1]
		table_remove(self.items, 1)
		self.size = self.size - 1
		return item
	end
	return nil
end

function Queue:Contains(item)
	for i = 1, self.size do
		local _item = self.items[i]
		if _item == item then return true end
	end
	return false
end

function Queue:Clear()
	self.size = 0
	self.items = {}
end

function Queue:Count()
	return self.size
end

function Queue:IsEmpty()
	return self.size <= 0
end

-- 遍历元素做操作
function Queue:ForEach(func)
	-- body
end

return Queue